/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package FEMShapeFunction1D;

import Integration.IFunction1D;

/**
 *
 * @author mark_o
 */
public class FEMShapeFunction1D1 implements IFunction1D{
    double xi;
    double h;

    public FEMShapeFunction1D1(double xi, double h) {
        this.xi = xi;
        this.h = h;
    }

    public double calculate(double x) {
        if(x<xi){
            return 1+(x-xi)/h;
        }else{
            return 1+(-x+xi)/h;
        }
    }

    public double calculateDerivaty(double x) {
        if(xi-x>0){
            return 1.0/h;
        }else{
            return -1.0/h;
        }
    }

    public double getH() {
        return h;
    }

    public double getXi() {
        return xi;
    }

    public static void main(String[] args){
        //ArrayList<Double> list = new ArrayList<Double>();
        double a = 0;
        double b = 1;
        int N = 50;
        double h = (b-a)/N;
        //for (int i = 0; i <= N; i++) {
        //    list.add(a+h*i);
        //}
        FEMShapeFunction1D1 f = new FEMShapeFunction1D1(0.5, 0.5);
        for (int i = 0; i <= N; i++) {
            System.out.println((a+h*i)+"\t\t"+f.calculate(a+h*i));
        }

    }

}
